<template>
<slot :controller="controller" :store="store" :model="model">
  <GRIDVIEWTEST v-bind="$attrs" :controller="controller" :store="store">
    <template #toolbar="{ controller }">
  	  <slot name="ViewToolbar" :controller="controller" :store="store" :model="model" :actions="{ handleToolbarItemClick }">
  	      <AppToolbar
  	          name="toolbar"
  	          mode="GRIDVIEWTEST"
  	          :items="store.toolbarItems"
  	          :loading="store.loadingHelper.isLoading"
  	          @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
  	      </AppToolbar>
  	  </slot>
    </template>
    <template #grid="{ controller }">
  	  <slot name="IBIZBOOKMainGrid" :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
  	  <IBIZBOOKMainGrid
  	      :rowActiveMode='model.rowActiveMode'
  	      :actions="{
  	          loadDraftAction: 'GetDraft',
  	          createAction: 'Create',
  	          fetchAction: 'FetchDefault',
  	          removeAction: 'Remove',
  	          updateAction: 'Update'
  	      }"
  	      :defaultEnableRowEdit="model.rowEditDefault"
  	      :openView="store.openView"
  	      :newView="store.newView"
  	      :singleSelect="false"
  	      name="grid"
  	      v-bind="model.ctrlParams.IBIZBOOKgrid"
  	      :context="store.context"
  	      :viewParams="store.viewParams"
  	      :closeView="store.closeView"
  	      :pLoadingHelper="store.loadingHelper"
  	      :pViewCtx="store.viewCtx"
  	      @ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
  	      @ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
  	      @ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"></IBIZBOOKMainGrid>
  	  </slot>
    </template>
    <template #searchform="{ controller }">
    </template>
  </GRIDVIEWTEST>
</slot>
</template>
<script setup lang="ts">
// 基于template/src/views/{{appModules}}/{{pages@DEGRIDVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppMDViewLayout } from '@components/layout/md-view-layout';
import GRIDVIEWTEST from "@plugins/view/gridviewtest/gridviewtest.vue";
import { AppToolbar } from '@components/widgets/toolbar';

import IBIZBOOKMainGrid from '@widgets/ibizbook/main-grid/main-grid.vue';
import IBIZBOOKQUICKSEARCHFORMSearchForm from '@widgets/ibizbook/quicksearchform-searchform/quicksearchform-searchform.vue';
import { useProps, useBasic, useAction, useController } from './ibizbook-usr-grid-view-plugin-hook';
import { IEvent, GridViewActionType, IGridViewAbility, IGridViewStore, IParam } from '@/core';

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { getClassNames, 
	getSearchFormSlotName, 
	model, 
	useNavParamsBind,
	useEventBind,
  	handleQuickGroupValueChange,
  	handleQuickSearch,
  	handleToolbarItemClick,
    handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy 
	} = useBasic(props);

const emit = defineEmits<{
    (event: 'view-action', name: string, action: GridViewActionType, data: IParam[]): void;
    (event: 'view-init', name: string, data: IGridViewAbility): void;
    (event: 'view-mounted', name: string, data: IParam): void;
    (event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  	return getClassNames(props);
});

const searchFormSlotName = computed(() => {
  	return getSearchFormSlotName(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IGridViewStore = controller.getStore();

onMounted(() => {
    controller.viewMounted();
})

onUnmounted(() => {
    controller.viewDestroy();
})
</script>
